package com.guc.coroutines

import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import com.king.zxing.CaptureActivity
import com.king.zxing.camera.FrontLightMode

class ScanCaptureActivity : CaptureActivity() {
    override fun getLayoutId(): Int = R.layout.activity_scan_capture
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.apply {
            setDisplayHomeAsUpEnabled(true)

        }
        captureHelper.playBeep(false) //音效
            .vibrate(true) //震动
            .frontLightMode(FrontLightMode.AUTO)
            .supportLuminanceInvert(true)
    }

    override fun onResultCallback(result: String): Boolean {
        val intent = Intent()
        intent.putExtra("result", result)
        setResult(RESULT_OK, intent)
        finish()
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> finish()
        }
        return super.onOptionsItemSelected(item)
    }
}